/*
 * xstring.cpp
 *
 *  Created on: Sep 26, 2011
 *      Author: lindenb
 */
#include <cstring>
#include "xstring.h"

using namespace std;


CStringReader::CStringReader(const char* s,std::size_t len):str(s),len(len),curr(0UL)
	{

	}
CStringReader::CStringReader(const char* s):str(s),len(strlen(s)),curr(0UL)
	{

	}
int CStringReader::eof()
	{
	return(curr>=len?1:0);
	}
CStringReader::~CStringReader()
	{
	}
void CStringReader::close()
	{
	curr=len;
	}
int CStringReader::getc()
	{
	return(curr>=len?EOF:str[curr++]);
	}

std::size_t XCString::split(char *line,const char* delim,std::vector<char*>& tokens)
    {
    char *p=line;
    tokens.clear();
    tokens.push_back(line);
    while(*p!=0)
	{
	if(strchr(delim,*p)!=NULL)
	    {
	    tokens.push_back((p+1));
	    *p=0;
	    }
	++p;
	}
    return tokens.size();
    }

std::size_t XCString::split(const char *line,const char* delim,std::vector<std::string>& tokens)
    {
    char *p=(char*)line;
    const char* prev=line;
    tokens.clear();

    for(;;)
	{
	if(*p==0 || strchr(delim,*p)!=NULL)
	    {
	    tokens.push_back(string(prev,p-prev));
	    if(*p==0) break;
	    prev=p+1;
	    }
	++p;
	}
    return tokens.size();
    }

